package JSE_02.Map.Demo04;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo01HashMapSavePerson {
    public static void main(String[] args) {
//        show00();
        show01();
    }

    public static void show00(){
        HashMap<String,Person> map=new HashMap<>();
        // 字符串重写了hashCode和equals方法 可以保证key唯一
        map.put("北京",new Person("小红",19));
        map.put("上海",new Person("小美",21));
        map.put("南京",new Person("小婷",28));
        map.put("北京",new Person("小莉",30));

        Set<String> set=map.keySet();
        for(String key:set){
            Person value=map.get(key);
            System.out.println(key+"=>"+value);
        }
    }

    public static void show01(){
        HashMap<Person,String> map=new HashMap<>();
        map.put(new Person("小红",19),"北京");
        map.put(new Person("小美",21),"上海");
        map.put(new Person("小婷",28),"南京");
        map.put(new Person("小红",19),"北京");

        Set<Map.Entry<Person,String>> set = map.entrySet();
        for(Map.Entry<Person,String> entry:set){
            Person key=entry.getKey();
            String value=entry.getValue();
            System.out.println(key+"=>"+value);
        }
    }
}
